#include "setting.h"
#include "dcuinformation.h"
#include <QLabel>

Setting::Setting(QWidget *parent) : QWidget(parent)
{
    setWindowFlags(Qt::FramelessWindowHint);
    setAutoFillBackground(true);
    QPalette background = palette();
    background.setBrush(QPalette::Window, QBrush(QPixmap(":/images/defaultUI.png")));
    setPalette(background);

    QLabel *emergencyText = new QLabel(this);
    emergencyText->setText(tr("紧急广播"));
    emergencyText->setFont(QFont(ZITI, 20, QFont::Bold));
    emergencyText->setGeometry(QRect(215, 30, 115, 49));
    emergencyText->setStyleSheet("color:white");

    QLabel *emergencyImage = new QLabel(this);
    emergencyImage->setText(tr(""));
    emergencyImage->setFont(QFont(ZITI, 12, QFont::Bold));
    emergencyImage->setGeometry(QRect(320, 2, 100, 100));
    emergencyImage->setStyleSheet("color:white;border-image:url(:/images/Emergency Broadcast.png)");

    emergencyBox = new QComboBox(this);
    emergencyBox->setFont(QFont(ZITI, 15, QFont::Normal));
    emergencyBox->setGeometry(QRect(410, 35, 200, 40));
    emergencyBox->setStyleSheet("QScrollBar:vertical {width:30px;}");

    QLabel *crashText = new QLabel(this);
    crashText->setText(tr("应急广播"));
    crashText->setFont(QFont(ZITI, 20, QFont::Bold));
    crashText->setGeometry(QRect(215, 100, 115, 49));
    crashText->setStyleSheet("color:white");

    QLabel *crashImage = new QLabel(this);
    crashImage->setText(tr(""));
    crashImage->setFont(QFont(ZITI, 12, QFont::Bold));
    crashImage->setGeometry(QRect(320, 72, 100, 100));
    crashImage->setStyleSheet("color:white;border-image:url(:/images/meet an emergency.png)");

    crashBox = new QComboBox(this);
    crashBox->setFont(QFont(ZITI, 15, QFont::Normal));
    crashBox->setGeometry(QRect(410, 105, 200, 40));
    crashBox->setStyleSheet("QScrollBar:vertical {width:30px;}");

    QPushButton *okBtn = new QPushButton(this);
    okBtn->setText("确定");
    okBtn->setGeometry(QRect(470, 350, 150, 50));
    okBtn->setFont(QFont(ZITI, 18, QFont::Normal));
    connect(okBtn, SIGNAL(clicked()), this, SLOT(okBtnDone()));

    QPushButton *backBtn = new QPushButton(this);
    backBtn->setText("返回");
    backBtn->setGeometry(QRect(620, 350, 150, 50));
    backBtn->setFont(QFont(ZITI, 18, QFont::Normal));
    connect(backBtn, SIGNAL(clicked()), this, SLOT(backBtnDone()));
}

void Setting::setAudioList(QStringList audioList)
{
    static QStringList tempVar;
    if (tempVar != audioList)
    {
        tempVar = audioList;
        if (!audioList.isEmpty())
        {
            emergencyBox->clear();  //清除老的预录列表
            crashBox->clear();
            foreach (QString audio, audioList)
            {
                emergencyBox->addItem(audio);
                crashBox->addItem(audio);
            }
        }
    }
}

void Setting::setCurrentComBox(int emergencyIndex, int crashIndex)
{
    emergencyBox->setCurrentIndex(emergencyIndex);
    crashBox->setCurrentIndex(crashIndex);
}

void Setting::backBtnDone()
{
    emit pageInfo("返回");
}

void Setting::okBtnDone()
{
    emit emergencyInfo(emergencyBox->currentIndex(), crashBox->currentIndex());
    msgBoxShow("设置成功");
}

void Setting::msgBoxShow(QString msg)
{
    if (!msgBox.isVisible())
    {
        msgBox.setText(msg);
        msgBox.setFont(QFont(ZITI, 20, QFont::Bold));
        msgBox.setStyleSheet("color:white;text-align:center;");
        msgBox.show();
    }
}
